package com.soxing.braindata.web.controller;

// src/main/java/com/example/demo/controller/ErrorController.java
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

@Controller
public class MyErrorController implements ErrorController {

    @RequestMapping("/error")
    public ModelAndView handleError(HttpServletRequest request) {
        Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
        ModelAndView mav = new ModelAndView();

        mav.setViewName("error"); // 对应 templates/error.html
        mav.addObject("statusCode", statusCode);

        // 可以向页面传递一些信息
        mav.addObject("path", request.getAttribute("javax.servlet.error.request_uri"));
        mav.addObject("statusCode", statusCode);

        return mav;
    }
}
